#define _CRT_SECURE_NO_WARNINGS

#include "string.h"

void test_string1()
{
	hb::string s1("hello world");
	cout << s1.c_str() << endl;

	hb::string::iterator it = s1.begin();
	while (it != s1.end())
	{
		cout << *it << " ";
		it++;
	}
	cout << endl;

	for (auto e : s1)
	{
		cout << e << " ";
	}
	cout << endl;
}

void test_string2()
{
	hb::string s1("hello world");
	cout << s1.c_str() << endl;

	s1.push_back('x');
	cout << s1.c_str() << endl;

	s1.append("yyyy");
	cout << s1.c_str() << endl;

	s1 += 'm';
	s1 += "nnn";

	cout << s1.c_str() << endl;
}

void test_string3()
{
	hb::string s1("hello world");
	s1.push_back('x');
	s1.append("xxx");
	s1.insert(0, "yyy");
	cout << s1.c_str() << endl;
}

void test_string4()
{
	hb::string s1("hello world");
	hb::string s2("hello world");
	s1.erase(6);
	cout << s1.c_str() << endl;

	s2.erase(6, 3);
	cout << s2.c_str() << endl;
}

void test_string5()
{
	hb::string s1("hello world");
	
	cout << s1.find('o') << endl;
	cout << s1.find("world") << endl;
}

void test_string6()
{
	hb::string s1("hello world");
	hb::string s2(s1);

	s1[0] = 'x';

	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;
}

void test_string7()
{
	hb::string s1("hello world");
	hb::string s2("hhh");

	s2 = s1;

	s1[0] = 'x';

	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;
}

void test_string01()
{
	//string s3 = "https://cplusplus.com/reference/string/string/rfind/";
	hb::string s3 = "https://blog.csdn.net/qq_74319491/article/details/137381843?spm=1001.2014.3001.5501";
	size_t i1 = s3.find(':');
	hb::string sub1, sub2, sub3;

	if (i1 != string::npos)
		sub1 = s3.substr(0, i1);

	size_t i2 = s3.find('/', i1 + 3);
	if (i2 != string::npos)
		sub2 = s3.substr(i1 + 3, i2 - i1 - 3);
	
	size_t i3 = s3.find('/', i2 + 1);
	if (i3 != string::npos)
		sub3 = s3.substr(i2 + 1);

	cout << sub1.c_str() << endl << sub2.c_str() << endl << sub3.c_str() << endl;
}

void test_string8()
{
	hb::string s("hello world");
	cin >> s;
	cout << s << endl;
}

void test_string9()
{
	hb::string s1("hello world");
	s1.resize(5);
	cout << s1 << endl;
	s1.resize(10, 'x');
	cout << s1 << endl;
}

void test_string10()
{
	hb::string s1("xxx");
	s1.push_back('y');
	cout << s1.size() << " " << s1.capacity() << endl;
	s1.shrink_to_fit();
	cout << s1.size() << " " << s1.capacity() << endl;
}

void test_string02()
{
	hb::string s("hello world");
	getline(cin, s);
	cout << s << endl;
}

int main()
{
	test_string02();

	return 0;
}